package yartiss.engine.simulation.logger;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import yartiss.engine.simulation.Event;

public class Logger {
	
	private static Logger instance = new Logger();
	private Writer writer;
	private boolean isEnabled = false;
	
	
	public static Logger instance(){
		return instance;
	}
	
	private Logger(){
		try {
			writer = new FileWriter("log.txt");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void log(Event e, String str){
		if(isEnabled){
			String s = e.getDate()+" : t"+e.getTask().getId()+" : "+ e+" : procId="+e.getProcId()+" : "+str;
			System.out.println(s);
			try {
				writer.write(s+"\n");
				writer.flush();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	
	public void setEnabled(boolean enabled){
		isEnabled = enabled;
	}
}
